<?php
/*
 * Copyright (c) 2021.  Liuhongbin All rights reserved.
 * @domain http://dkyx.cc
 * @author liuhongbin <514660094@qq.com>
 */

namespace app\common\model\open;


use app\common\model\addon\Addons;
use app\common\model\BaseModel;

class OpenTemplate extends BaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 字段类型或者格式转换
     * @var array
     */
    protected $type = [
        'config' => 'json',
    ];

    public $_types = [
        0 => "系统插件",
        1 => "微信公众平台",
        2 => "小程序",
        3 => "企业微信",
        4 => "抖音H5",
        5 => "独立平台"
    ];

    public $childFields = ['open_id'];

    /**
     * 微信小程序隐私协议列表
     * @var string[]
     */
    public $wechatMinAppPrivacyList = [
        'UserInfo'             => '用户信息（微信昵称、头像）',
        'Location'             => '位置信息',
        'Address'              => '地址',
        'Invoice'              => '发票信息',
        'RunData'              => '微信运动数据',
        'Record'               => '麦克风',
        'Album'                => '选中的照片或视频信息',
        'Camera'               => '摄像头',
        'PhoneNumber'          => '手机号码',
        'Contact'              => '通讯录（仅写入）权限',
        'DeviceInfo'           => '设备信息',
        'EXIDNumber'           => '身份证号码',
        'EXOrderInfo'          => '订单信息',
        'EXUserPublishContent' => '发布内容',
        'EXUserFollowAcct'     => '所关注账号',
        'EXUserOpLog'          => '操作日志',
        'AlbumWriteOnly'       => '相册（仅写入）权限',
        'LicensePlate'         => '车牌号',
        'BlueTooth'            => '蓝牙',
        'CalendarWriteOnly'    => '日历（仅写入）权限',
        'Email'                => '邮箱',
        'MessageFile'          => '选中的文件',
        'ChooseLocation'       => '选择的位置信息',
        'Accelerometer'        => '加速传感器',
        'Compass'              => '磁场传感器',
        'DeviceMotion'         => '方向传感器',
        'Gyroscope'            => '陀螺仪传感器',
        'Clipboard'            => '剪切板'
    ];

    public function open()
    {
        return $this->belongsTo(Open::class, 'open_id', 'id');
    }

    public function getAddonAttr($val, $data)
    {
        return (new Addons())->where(['name' => $data['addon_name']])->find();
    }
}
